#include <cstdio>
using namespace std;
//TODO:...

int n, t, x, y, val;
char dir;
int map[4][4];
int main() {
	freopen("game.in", "r", stdin);
	freopen("game.out", "w", stdout);
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d%d%c", &x, &y, &val, &dir);
		map[x][y] = val;
		switch (dir) {
		case 'L':
			for (int i = 0; i < 4; ++i) {
				int cnt = 0;
				for (int j = 0; j < 4; ++j) {
					if (map[i][j] == map[i][j + 1]) {
						map[i][j] = map[i][j + 1] = 0;
						map[i][cnt++] = map[i][j] << 1;
					} else {
						map[i][j] = map[i][j + 1];
					}
				}
			}
			break;
		case 'U':
			for (int i = 0; i < 4; ++i) {
				int cnt = 0;
				for (int j = 0; j < 4; ++j) {
					if (map[j][i] == map[j + 1][i]) {
						map[j][i] = map[j + 1][i] = 0;
						map[cnt++][i] = map[j][i] << 1;
					} else {
						map[i][j] = map[i + 1][j];
					}
				}
			}
			break;
		case 'R':
			for (int i = 0; i < 4; ++i) {
				int cnt = 4;
				for (int j = 4; j; --j) {
					if (map[i][j] == map[i][j - 1]) {
						map[i][j] = map[i][j - 1] = 0;
						map[i][cnt--] = map[i][j] << 1;
					} else {
						map[i][j] = map[i][j - 1];
					}
				}
			}
			break;
		case 'D':
			for (int i = 0; i < 4; ++i) {
				int cnt = 4;
				for (int j = 4; j; --j) {
					if (map[j][i] == map[j - 1][i]) {
						map[j][i] = map[j - 1][i] = 0;
						map[cnt--][i] = map[j][i] << 1;
					} else {
						map[i][j] = map[i - 1][j];
					}
				}
			}
			break;
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				printf("%d ", map[i][j]);
			}
			puts("");
		}
		return 0;
	}
}